package com.itheima.service.impl;

import com.itheima.jopo.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * DeptServiceImpl
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/4/29 10:01
 */
@Service
public class DeptServiceImpl implements DeptService {

    private final DeptMapper deptMapper;

    public DeptServiceImpl(DeptMapper deptMapper) {
        this.deptMapper = deptMapper;
    }

    @Override
    public List<Dept> list() {
        // 数据库直接取数据
        return deptMapper.selectList();
    }

    @Override
    public void removeById(String id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void addOne(Dept dept) {
        // 为什么要在这里添加这两个时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertOne(dept);
    }
}
